package com.scatteredServer.handler;


import com.scatteredServer.common.Result;
import com.scatteredServer.exception.FileException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    private final static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    //假装 只有默认出错的错误状态码为201
    @ExceptionHandler(value = RuntimeException.class)
    public Result<?> BaseException(RuntimeException e){
        e.printStackTrace();
        logger.error(e.getMessage());
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(value = FileException.class)
    public Result<?> FileException(FileException e){
        e.printStackTrace();
        logger.error(e.getMessage());
        return Result.fail(404,"文件错误",null);
    }


}
